Make Navigon reader use QString more effectively.
authorrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sun, 20 Oct 2013 23:31:16 +0000 (23:31 +0000)
committerrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sun, 20 Oct 2013 23:31:16 +0000 (23:31 +0000)
git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4633 f51c46e8-681c-474f-0cfe-069cfd0219fb

gpsbabel/nmn4.cc

index 1aac5346da8113b44bb025c1c5b8723238009f4f..d34afe1951482d8b97995ff0a091e39d96ffb42f 100644 (file)
@@ -50,7 +50,7 @@ arglist_t nmn4_args[] = {
 /* helpers */
 
 static char*
-nmn4_concat(char* arg0, ...)
+nmn4_concat(const char* arg0, ...)
 {
   va_list args;
   char* src, *res;
@@ -70,7 +70,7 @@ nmn4_concat(char* arg0, ...)
         res = xstrappend(res, c);
       }
     }
-    xfree(src);
+//    xfree(src);
     src = va_arg(args, char*);
   }
   va_end(args);
@@ -95,11 +95,12 @@ static void
 nmn4_read_data(void)
 {
   char* buff;
-  char* str, *c;
+  char* str;
+  QString c;
   int column;
   int line = 0;
 
-  char* zip1, *zip2, *city, *street, *number;
+  QString zip1, zip2, city, street, number;
   route_head* route;
   waypoint* wpt;
 
@@ -118,12 +119,12 @@ nmn4_read_data(void)
     nmn4_check_line(buff);
 
     /* for a quiet compiler */
-    zip1 = zip2 = city = street = number = NULL;
+    zip1 = zip2 = city = street = number = QString();
 
     wpt = waypt_new();
 
     column = -1;
-    c = csv_lineparse(str, "|", "", column++);
+    c = QString::fromLatin1(csv_lineparse(str, "|", "", column++));
     while (c != NULL) {
       switch (column) {
       case  0: /* "-" */       /* unknown fields for the moment */
@@ -138,46 +139,36 @@ nmn4_read_data(void)
         break;
 
       case  4:                                 /* ZIP Code */
-        if (*c != '-') {
-          zip1 = xstrdup(c);
-        } else {
-          zip1 = xstrdup("");
+        if (c[0] != '-') {
+          zip1 = c;
         }
         break;
 
       case  5:                                 /* City */
-        if (*c != '-') {
-          city = xstrdup(c);
-        } else {
-          city = xstrdup("");
+        if (c[0] != '-') {
+          city = c;
         }
         break;
 
       case  6:                                 /* ZIP Code -2- */
-        if (*c != '-') {
-          zip2 = xstrdup(c);
-        } else {
-          zip2 = xstrdup("");
+        if (c[0] != '-') {
+          zip2 = c;
         }
         break;
 
       case  7:                                 /* Street */
-        if (*c != '-') {
-          street = xstrdup(c);
-        } else {
-          street = xstrdup("");
+        if (c[0] != '-') {
+          street = c;
         }
         break;
 
       case  8:                                 /* Number */
-        if (*c != '-') {
-          number = xstrdup(c);
-        } else {
-          number = xstrdup("");
+        if (c[0] != '-') {
+          number = c;
         }
 
         /*
-                  This is our final index
+           This is our final index
            All stuff for generating names or comments
            is hold locally.
 
@@ -185,32 +176,40 @@ nmn4_read_data(void)
            Instead we construct a description from that.
         */
 
-        if (strcmp(zip1, zip2) == 0) {
-          *zip2 = '\0';
+        if (zip1 == zip2) {
+          zip2 = QString();
         }
-        if (*city != '\0') {
+        if (!city.isEmpty()) {
           /*
           if any field following city has a value, add a comma to city
           */
-          if ((*street != '\0') || (*number != '\0') || (*zip2 != '\0')) {
-            city = xstrappend(city, ",");
+          if (!street.isEmpty() || !number.isEmpty() || !zip2.isEmpty()) {
+            city += ",";
           }
         }
 
         /* concats all fields to one string and release */
-        wpt->description = nmn4_concat(zip1, city, street, number, zip2, NULL);
+#if NEW_STRINGS
+        wpt->description = zip1.trimmed() + " " +
+          city.trimmed() + " " +
+          street.trimmed() + " " +
+          number.trimmed() + " " +
+          zip2.trimmed();
+#else
+        wpt->description = nmn4_concat(CSTR(zip1), CSTR(city), CSTR(street), CSTR(number), CSTR(zip2), NULL);
+#endif
         break;
 
       case 11:                                 /* longitude */
-        sscanf(c, "%lf", &wpt->longitude);
+        wpt->longitude = c.toDouble();
         break;
 
       case 12:                                 /* latitude */
-        sscanf(c, "%lf", &wpt->latitude);
+        wpt->latitude = c.toDouble();
         break;
 
       }
-      c = csv_lineparse(NULL, "|", "", column++);
+      c = QString::fromLatin1(csv_lineparse(NULL, "|", "", column++));
     }
     route_add_wpt(route, wpt);
   }